/*

Author   : chaos

FileName : stl_set.cpp

Date     : 17/08/17 10:23:07

*/
#include <iostream>
#include <string>
#include <iterator>
#include <set>
using namespace std;

typedef set<string ,less<string> > str_set;

template <class T>

void print(set<T> & pri_con)
{
    if(pri_con.empty())
        cout << "Container is empty !" << endl;
    else
    {
        typename set<T>::iterator i;

        for( i = pri_con.begin() ; i != pri_con.end() ; i++ )
        {
            cout << *i << " ";
        }
        cout << endl;
    }
}
int main(int argc ,char *argv[])
{
    string name[] = {"Mary","John","Ann","Joe","Ken"};
    str_set s(name,name +5);
    print (s);

    s.insert("Judy");
    print(s);

    string search,upper,lower;
    str_set::iterator iter;

    cout << "Please input name for searching : " << endl;
    cin >> search;

    iter = s.find(search);
    if(iter == s.end())
        cout << "The " << search << " is not in container !" << endl;
    else
        cout << "The " << search << "is in container !" << endl;

    cout << "Please input a range for searching :(Upper/Lower)" << endl;
    cin >> upper >> lower;

    for(iter = s.lower_bound(lower); iter != s.upper_bound(upper) ; iter++)
    {
        cout << *iter << " " ;
    }

    cout << endl;

    return 0;
}
